package ma.co.cdm.esign.workers;

import ma.co.cdm.esign.vo.MySisSolrDoc;
import ma.co.cdm.esign.vo.SolrBean;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SolrIndexService {
	
	Logger logger = LoggerFactory.getLogger(SolrIndexService.class);
	
	private Configuration appconfig;
	
	public Configuration getAppconfig() {
		return appconfig;
	}

	public void setAppconfig(Configuration appconfig) {
		this.appconfig = appconfig;
	}

	public void indexDocument(SolrBean doc)
	{
		if(doc instanceof MySisSolrDoc && doc != null)
		{
			//Indexing document
			logger.info("Indexing document : "+((MySisSolrDoc)doc).getPathFsXml());		
		    try {				
			  appconfig.getServer().addBean(doc);
			  appconfig.getServer().commit();
			 }
             catch (Exception e) {
				logger.error(e.getMessage(),e);
			 }
		}		
	}
}
